package net.towee.server.persistence;

import net.towee.model.bittorrent.TorrentData;
import net.towee.shared.exceptions.PersistenceException;

/**
 * The store of registred torrents and active peers
 * 
 * @author c58
 */
public interface TorrentStore {
	/**
	 * Create new torrent in datastore
	 * 
	 * @param torrent
	 * @return true if torrent with given infoHash not exists
	 */
	boolean createTorrent(TorrentData torrent);

	/**
	 * Update torrent data
	 * 
	 * @param torrent
	 * @return true on success
	 */
	boolean updateTorrent(TorrentData torrent);
	
	/**
	 * Remove torrent with given infoHash
	 * @param infoHash
	 * @return
	 */
	boolean removeTorrent(String infoHash);
	
	/**
	 * Get torrent with given infoHash and return it or null if
	 * torrent not exists
	 * 
	 * @param infoHash
	 * @return
	 * @throws PersistenceException 
	 */
	TorrentData getTorrent(String infoHash) throws PersistenceException;

	/**
	 * @return iterable instance of all torrents in db, which contains at least
	 *         one pear
	 */
	Iterable<TorrentData> getTorrents();
}
